from ..extensions import db

class Inventory(db.Model):
    """库存数据模型"""
    __tablename__ = 'inventory'
    id = db.Column(db.Integer, primary_key=True)
    material_type = db.Column(db.String(50), index=True)  # 类型字段
    item_code = db.Column(db.String(100), unique=True)
    quantity = db.Column(db.Integer)
    update_time = db.Column(db.DateTime, default=db.func.now())

    def to_dict(self):
        """模型转字典方法"""
        return {
            'id': self.id,
            'type': self.material_type,
            'item_code': self.item_code,
            'quantity': self.quantity,
            'update_time': self.update_time.isoformat()
        }